/*
 * Part of the ACID Project
 * Developed in 2011 by Morgan Taschuk
 */

/*
 * AcidResultsPanel.java
 *
 * Created on 31-May-2011, 11:22:43
 */
package acid.plugin.gui;

import components.ButtonTabComponent;
import cytoscape.Cytoscape;
import cytoscape.view.cytopanels.CytoPanelImp;
import cytoscape.view.cytopanels.CytoPanelState;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

/**
 *
 * @author morgan
 */
public class AcidResultsPanel extends javax.swing.JPanel
{

    private static AcidResultsPanel instance = null;
    private CytoPanelImp resultsPanel = null;

    public static AcidResultsPanel getInstance()
    {
        if (instance == null)
        {
            instance = new AcidResultsPanel();
        }
        return instance;
    }

    /** Creates new form AcidResultsPanel */
    private AcidResultsPanel()
    {
        initComponents();
        this.add(new LegendPanel(), BorderLayout.SOUTH);
        //First, get a handler to the cytoPanel east, which is the results panel
        resultsPanel = (CytoPanelImp) Cytoscape.getDesktop().
                getCytoPanel(SwingConstants.EAST);
        resultsPanel.add("ACID", this);
        resultsPanel.setSelectedIndex(resultsPanel.getCytoPanelComponentCount() - 1);
        resultsPanel.setState(CytoPanelState.DOCK);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jLabel1 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();

        jLabel1.setText("jLabel1");

        setMaximumSize(new java.awt.Dimension(2147483647, 500));
        setMinimumSize(new java.awt.Dimension(12, 500));
        setPreferredSize(new java.awt.Dimension(314, 500));
        setLayout(new java.awt.BorderLayout());
        add(jTabbedPane1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    public void addTab(String tabTitle, JPanel pane)
    {
        if (jTabbedPane1.getTabCount() == 1 && jTabbedPane1.getTitleAt(0).equals("tab1"))
        {
            jTabbedPane1.removeTabAt(0);
        }
        int count = 0;
        for (int i = 0; i < jTabbedPane1.getTabCount(); i++)
        {
            if (jTabbedPane1.getTitleAt(i).contains(tabTitle))
            {
                count++;
            }
        }
        if (count > 0)
        {
            tabTitle += " (" + (count + 1) + ")";
        }

        jTabbedPane1.insertTab(tabTitle, null, pane, tabTitle, 0);
        jTabbedPane1.setTabComponentAt(0, new ButtonTabComponent(jTabbedPane1));

        resultsPanel.setState(CytoPanelState.DOCK);

    }

    public void showLegend(boolean show)
    {
        //legendPanel.setVisible(show);
        resultsPanel.setState(CytoPanelState.DOCK);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTabbedPane jTabbedPane1;
    // End of variables declaration//GEN-END:variables
}
